package zhaomh.zlogin;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.io.IOException;

import static zhaomh.zlogin.Tools.PLUGIN;

public class Data {
    // bukkit默认config文件

    // bukkit默认config文件中language选项的key 详细可以看方法getLanguage
    public static FileConfiguration config;
    private static final File config_file = new File(PLUGIN.getDataFolder(),"config.yml");
    // 自定义配置文件
    public static YamlConfiguration data;
    private static final File data_file = new File(PLUGIN.getDataFolder(),"data.yml");;
    private Data() {
        reloadConfigs();
    }
    public static void reloadConfigs(){
        // 读取bukkit默认config文件
        config = PLUGIN.getConfig();
        // 读取自定义config文件
        data = YamlConfiguration.loadConfiguration(data_file);
    }
    public static void saveConfigs() {
        try {
            //保存bukkit默认的config文件
            config.save (config_file);
            //保存自定义配置文件
            data.save (data_file);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        reloadConfigs();
    }
    public static void initialize(){
        reloadConfigs();
        saveConfigs();
    }
}
